import 'package:flutter_blue/flutter_blue.dart';


class MyEvent{
  final String name;
  final Function callback;

  late BluetoothDevice device;

  MyEvent(this.name,this.callback);

}

class GlobalSeer{

  static List<MyEvent?> events=[];

  static void addEventListener(String eventName,Function callback){
    bool exist=false;
    for(MyEvent? item in events){
      if(item!=null && item.name==eventName){
        exist=true;
        break;
      }
    }
    if(!exist){
      events.add(MyEvent(eventName,callback));
    }
  }

  static void dispatchEvent(String eventName,dynamic data){
    for(MyEvent? item in events){
      if(item!=null && item.name==eventName){
        item.callback(data);
        break;
      }
    }
  }

  static void removeEventListener(String eventName){
    for(MyEvent? item in events){
      if(item!=null && item.name==eventName){
        events.remove(item);
        item=null;
        break;
      }
    }
  }

}